﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Diagnostics;

using FMPCore;
using FMPCore.Interfaces;

namespace Server
{
    class Program
    {
        static void Main(string[] args)
        {
            // Set up tracing
            TextWriterTraceListener tr1 = new TextWriterTraceListener(System.Console.Out);
            Debug.Listeners.Add(tr1);

            try
            {
                // Register Address
                ServiceHost servHost = new ServiceHost(typeof(Message),
                    new Uri("net.tcp://localhost:8731/Server/Message"));


                // Service contract and binding

                servHost.AddServiceEndpoint(typeof(IMessage), new NetTcpBinding(SecurityMode.None), "");

                servHost.Open();

                // Keep the server in memory until any key is pressed
                Trace.WriteLine("FMP server activated. Press any key to exit.");
                Console.ReadKey(true);

                servHost.Close();
            }
            catch (AddressAlreadyInUseException addInUseEx)
            {
                Console.WriteLine("A process is already using the same address/port.");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }

        }
    }
}
